home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / ENTRY.SWG / 0016_Data Entry Routines.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-25  |  8KB  |  183 lines

  1. {
  2. Well, this code outlines your problem and it's solution. I assume
  3. you have a single string input procedure. However, why don't you just
  4. position several strings on the screen? The techinique I've outlined
  5. is legit, but a little cumbersome:
  6. (in two messages}
  7. {Regarding your request for a form input technique, I do not know
  8. of a library that handles this, although there probably is one.
  9. Such an object (in the loose sense of the word) could be written in
  10. Turbo Pascal, given a string input handler that you have the source
  11. to so you could modify the exit keys.
  12.    Imagine a procedure getstring that sets single string input that
  13. returns the string when Enter or Tab is pressed, sets a list to "commit"
  14. when enter is pressed as well, and sets a list to "cancel" when escape
  15. is
  16. pressed. Now you can set up a global record structure and skeleton
  17. for form input like so}
  18. program formit;
  19. uses crt;
  20.        type
  21.        single_string=record
  22.            startx,starty:byte; {start coordinates of each caption}
  23.            caption:string; {the caption for the string}
  24.            str:string; {the single string you are getting}
  25.            max_permitted:byte; {maximum length of field}
  26.            end;
  27.  
  28.        {an array storing the strings in the forms and their place
  29.        on the screen}
  30.        form_array_type=array[1..30] of single_string;
  31.  
  32.        {exit status for each string entered}
  33.        exitlist=(nocode,tabstop,cancel,commit);
  34.  
  35.        var
  36.        form_array:form_array_type; {our form with it's strings}
  37.        no_strings_in_form:byte; {how many active strings in form}
  38.        exitcode:exitlist;
  39.        x:byte;
  40.             Procedure getstring(var input_string:string;max_permitted:
  41.             byte;var exitcode:
  42.                                    exitlist);
  43.                 Begin
  44.                 {single string input procedure}
  45.                 {doen't care about the form structure}
  46.  
  47.                 End;
  48.         {SUB PROCEDURE SHOW_FORM}
  49.          procedure show_form(form_array:form_array_type;
  50.               no_strings_in_form:byte);
  51.             var
  52.             x:byte;
  53.             begin
  54.             for x:=1 to no_strings_in_form do
  55.                 begin
  56.                 gotoxy(form_array[x].startx,form_array[x].starty);
  57.                 write(form_array[x].caption);
  58.                 end;
  59.             end;
  60.         {SUB PROCEDURE GET_FORM}
  61.  
  62.             Procedure Get_form(var form_array:form_array_type;
  63.                   no_items:byte; var exitcode:exitlist);
  64.                var
  65.                  form_array_index:byte;
  66.                  current_string:string;
  67.                  max_permitted:byte;
  68.                  {SUB} procedure get_first_tab; {find top left string}
  69.                       {THESE SCAN PROCEDURES MAY SEEM A LITTLE OBSCURE,
  70.                       THEY ARE DESIGNED TO FIND THE NEXT STRING
  71.                       AND NEED TO BE DEBUGGED}
  72.                       var
  73.                       x:byte;
  74.                       lastx,lasty:byte;
  75.                       begin
  76.                       form_array_index:=1;
  77.                       lastx:=form_array[1].startx;
  78.                       lasty:=form_array[1].starty;
  79.                       for x:=2 to no_items do
  80.                           if (form_array[x].starty<=lasty) and
  81.                              (form_array[x].startx<=lastx) then
  82.                              begin
  83.                              lasty:=form_array[x].starty;
  84.                              lastx:=form_array[x].startx;
  85.                              form_array_index:=x;
  86.                              end;
  87.                       end;
  88.  
  89.                {SUB}  procedure get_next_tab;
  90.                       var
  91.                       found:boolean;
  92.                       x,lastx,lasty:byte;
  93.                       last_form_array_index:byte;
  94.                       begin
  95.                       found:=false;
  96.                       last_form_array_index:=form_array_index;
  97.                       lastx:=200;
  98.                       lasty:=200; {force values}
  99.                       for x:=1 to no_items do
  100.                           if
  101.                           (x<>last_form_array_index) and
  102.                           (form_array[x].starty<=lasty)
  103.                           and
  104.                           (form_array[x].startx<=lastx)
  105.                           and
  106.                           (form_array[x].starty>=
  107.                             form_array[last_form_array_index].starty)
  108.                             and
  109.                           (form_array[x].startx>=
  110.                             form_array[last_form_array_index].startx)
  111.                              then
  112.                                 begin
  113.                                   form_array_index:=x;
  114.                                   lasty:=form_array[form_array_index]
  115.                                   .starty;
  116.                                   lastx:=form_array[form_array_index].
  117.                                   startx;
  118.                                   found:=true;
  119.                                 end;
  120.                       if not found then
  121.                          get_first_tab;
  122.                       end;
  123.                Begin
  124.                {1. ? find the top left by
  125.                     scanning the startx, starty of form_array}
  126.                get_first_tab;
  127.                REPEAT
  128.  
  129.                  {2. Now write the string and get the new string}
  130.                  gotoxy(form_array[form_array_index].startx,
  131.                         form_array[form_array_index].starty);
  132.                  write(form_array[form_array_index].caption,
  133.                        form_array[form_array_index].str);
  134.                  gotoxy(form_array[form_array_index].startx+
  135.                  length(form_array[form_array_index].caption),
  136.                         form_array[form_array_index].starty);
  137.  
  138.                  current_string:=form_array[form_array_index].str;
  139.                  max_permitted:=form_array[form_array_index].
  140.                       max_permitted;
  141.                  exitcode:=nocode;
  142.                  {3. } Getstring(current_string,max_permitted,exitcode);
  143.  
  144.                  form_array[form_array_index].str:=current_string;
  145.  
  146.                  {4. ? find the next placed
  147.                       string to tab to by scanning the startx,
  148.                       starty of form array}
  149.                  if exitcode = tabstop then
  150.                       begin
  151.                       {? depends on x/y order in array};
  152.                       get_next_tab;
  153.                       end;
  154.  
  155.                 UNTIL exitcode in [cancel,commit];
  156.                 End; {get_form}
  157.  
  158.        Begin {Calling procedure}
  159.        {initialize array only has to be done once for the form
  160.        within scope}
  161.        no_strings_in_form:=5;
  162.        form_array[1].startx:=1;
  163.        form_array[1].starty:=3;
  164.        form_array[1].caption:='Name ';
  165.        form_array[1].str:='';
  166.        form_array[1].max_permitted:=20;
  167.        form_array[2].startx:=1;
  168.        form_array[2].starty:=4;
  169.        form_array[2].caption:='Address ';
  170.        form_array[2].str:='';
  171.        form_array[2].max_permitted:=60;
  172.        {ETCETERA}
  173.        {care must be taken not to overlap captions and strings}
  174.  
  175.        {the array is passed to the form input handler}
  176.        clrscr;
  177.        show_form(form_array,no_strings_in_form);
  178.        Get_form(form_array,no_strings_in_form,exitcode);
  179.  
  180.        {the new values of the strings are returned in
  181.        the array form_array, in each .str field}
  182.        End.
  183.